package views
{
	import assists.resource.ResourceLoaderData;
	
	import flash.display.Sprite;
	import flash.utils.getTimer;
	
	import inerface.ISinaWeiCo;
	
	import main.LocalStoreInfo;
	import main.ViewSubBase;
	
	import panel.sinaWeiCo.SinaWeiCoPanel;
	
	public class WeiCoView extends ViewSubBase
	{
		private var _panel:ISinaWeiCo;
		private var _isCommuteTime:Boolean;
		public function WeiCoView()
		{
			super();
		}
		
		override public function show():void
		{
		     render();
		}
		
		override protected function render():void
		{
			overTime();
		   if(!_panel)
		   {
			   _panel = new SinaWeiCoPanel();
			   _panel.init(layout.stage,resourceLoader,lang,this.data.uri);
			   _panel.onClose = layout.closeCurrent;
		   }
			   this.addView(_panel);
		   view.guide.upAndDownVisible(false,false);
		}
		
		private function overTime():void
		{
			if(_isCommuteTime) return;
			_isCommuteTime = true;
			var _localCahe:LocalStoreInfo = new LocalStoreInfo();
			var sinaInfo:Object = _localCahe.readInfo("sinaWeibo");
			var qqInfo:Object = _localCahe.readInfo("qqWeibo");
		    if(sinaInfo)
			{
				if(checkTime(3600 * 24 * 90 + sinaInfo.applyTime))
				{
					_localCahe.storeInfo("sinaWeibo",null);
				}
			}
			if(qqInfo)
			{
				if(checkTime(qqInfo.expires_in + qqInfo.applyTime))
				{
					_localCahe.storeInfo("qqWeibo",null);
				}
			}
		}
		
		private function checkTime(times:uint):Boolean
		{
			var nowTime:uint = getTimer();
			if(times - nowTime > 3600)
			{
				return false;
			}
			return true;
		}
		
		override public function clear():void
		{
			view.guide.upAndDownVisible(true,true);
			_panel.clear();
		}
		
	}
}